/* -----------------------------------------------------------------------
 * Don't forget to include the following lines in your makefile:
 *
 * testFileName: testFileName.c dominion.o rngs.o
 *      gcc -o testFileName -g  testFileName.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 *
 *  unittest3 tests the fullDeckCard() function
 *  This function didn't make sense to me, but I tested it as written in my
 *  dominion.c code, that it only gives the count of ONE SPECIFIC CARD in the
 *  full deck; the name to me implies that it counts ALL the cards a player has
 *  but the comments in the Dominion-BaseArchitecture.pdf indicates what I
 *  tested here.
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
//#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i, j;
    int seed = 1000;
    int numPlayer = 4;
    int cardCount[numPlayer];
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;

#if (NOISY_TEST == 1)
        printf("Testing fullDeckCount() function...\n");
#endif

    int game1 = initializeGame(numPlayer, k, seed, &G);
    assert(game1 == 0);
    for(i = 0; i < numPlayer; i++){
        //printf("Player %d: deckCount = %d, discardCount() = %d, handCount() = %d\n",i,G.deckCount[i],G.discardCount[i],G.handCount[i]);
        for(j = 0; j < 10; j++){
            assert(fullDeckCount(i,k[j],&G) == 0);
        }
        assert(fullDeckCount(i,copper,&G) == 7);
        assert(fullDeckCount(i,estate,&G) == 3);
    }

#if (NOISY_TEST == 1)
        printf("Initialized game successfully!!\n");
        printf("Adding kingdom cards to deck...\n");

#endif

    int c,d;
    for(i = 0; i < numPlayer; i++){
        c = G.deckCount[i];
        d = 0;
        for(j = c; j < c+5; j++){
            G.deck[i][j] = k[i];
            G.deckCount[i]++;
            d++;
            //printf("i = %d, j = %d, G.deckCount[i] = %d\n",i,j,G.deckCount[i]);
            assert(fullDeckCount(i,k[i],&G) == d);
        }
    }
#if (NOISY_TEST == 1)
        printf("Successful so far, adding more kingdom cards...\n");
#endif
    for(i = 0; i < numPlayer; i++){
        c = G.deckCount[i];
        d = 0;
        for(j = c; j < c+2; j++){
            G.deck[i][j] = k[i+5];
            G.deckCount[i]++;
            d++;
            assert(fullDeckCount(i,k[i+5],&G) == d);
        }
    }
#if (NOISY_TEST == 1)
        printf("Successful so far, adding more kingdom cards...\n");
#endif
    for(i = 0; i < numPlayer; i++){
        c = G.discardCount[i];
        d = 0;
        for(j = c; j < c+5; j++){
            G.discard[i][j] = k[i+2];
            G.discardCount[i]++;
            d++;
            assert(fullDeckCount(i,k[i+2],&G) == d);
        }
    }
#if (NOISY_TEST == 1)
        printf("Successful so far, adding more kingdom cards...\n");
#endif
    for(i = 0; i < numPlayer; i++){
        c = G.deckCount[i];
        d = 0;
        for(j = c; j < c+5; j++){
            G.deck[i][j] = k[i+6];
            G.deckCount[i]++;
            d++;
            assert(fullDeckCount(i,k[i+6],&G) == d);
        }
    }
#if (NOISY_TEST == 1)
        printf("Successful so far, adding silvers...\n");
#endif
    for(i = 0; i < numPlayer; i++){
        c = G.handCount[i];
        d = 0;
        for(j = c; j < c+3; j++){
            G.hand[i][j] = silver;
            G.handCount[i]++;
            d++;
            assert(fullDeckCount(i,silver,&G) == d);
        }
    }
#if (NOISY_TEST == 1)
        printf("Successful so far, adding golds...\n");
#endif
     for(i = 0; i < numPlayer; i++){
        c = G.handCount[i];
        d = 0;
        for(j = c; j < c+2; j++){
            G.hand[i][j] = gold;
            G.handCount[i]++;
            d++;
            assert(fullDeckCount(i,gold,&G) == d);
        }
    }
#if (NOISY_TEST == 1)
        printf("Successful golds...\n");
        printf("All tests passed!!!\n");
#endif

    return 0;
}
/*int fullDeckCount(int player, int card, struct gameState *state) {
  int i;
  int count = 0;

  for (i = 0; i < state->deckCount[player]; i++)
    {
      if (state->deck[player][i] == card) count++;
    }

  for (i = 0; i < state->handCount[player]; i++)
    {
      if (state->hand[player][i] == card) count++;
    }

  for (i = 0; i < state->discardCount[player]; i++)
    {
      if (state->discard[player][i] == card) count++;
    }

  return count;
}*/
